/**
 * 
 */
package com.java.test.user.mapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.java.test.user.dto.MemberInfo;

/**
 * @author Administrator
 *
 */
@Component
public class MemberInfoMapper {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<MemberInfo> selectMemberList(MemberInfo info) {

		StringBuffer sql = new StringBuffer();

		sql.append("select * from member_member where 1=1");

		if (info.getAccountType() != 0) {
			sql.append(" and account_type=?".replace("?", String.valueOf(info.getAccountType())));
		}

		if (info.getSliceValue() != 0) {
			sql.append(" and slice=?".replace("?", String.valueOf(info.getSliceValue())));
		}

		if (info.getArea() != null && !"".equals(info.getArea())) {
			sql.append(" and area=?".replace("?", info.getArea()));
		}

		if (info.getGradeValue() != 0) {
			sql.append(" and grade=?".replace("?", String.valueOf(info.getGradeValue())));
		}

		if (info.getMoenyType() != 0) {
			sql.append(" and money_type=?".replace("?", String.valueOf(info.getMoenyType())));
		}

		if (info.getContent() != null && !"".equals(info.getContent())) {
			sql.append(" and content like '%?%'".replace("?", String.valueOf(info.getContent())));
		}

		List<MemberInfo> list = jdbcTemplate.query(sql.toString(), new MemberInfo());

		return list;
	}

	// 总注册用户
	public int selectuserRegistCount(LocalDateTime startTime, LocalDateTime endTime) {

		String sql = "select count(*) from member_member where 1=1 ";

		String sqlitem = "";
		if (startTime == null && endTime == null) {
			sqlitem += " and TO_DAYS(register_time) = TO_DAYS(NOW())";
		} else {
			if (startTime != null)
				sqlitem += " and register_time >='" + startTime + "'";

			if (endTime != null)
				sqlitem += " and register_time <='" + endTime + "'";
		}
		int count = jdbcTemplate.queryForObject(sql + sqlitem, Integer.class);

		return count;
	}

	// 总注册用户
	public int selectuserallRegistCount() {

		String sql = "select count(*) from member_member where 1=1 ";

		int count = jdbcTemplate.queryForObject(sql, Integer.class);

		return count;
	}

	
	
	
	
}
